<?php
/*** WELCOME WIDGET *****************/
/*
Plugin Name: NG BP Advanced Welcome Widget
Plugin URI: http://blog.ngcorp.de/downloads/bp-downloads/
Description: This plugin provides the possibility to have a second who's online widget.  For the realisation i copyed the code from the bp-core-widget.php (line xx to xx). 
Author: ng
Version: 0.1
Author URI: http://blog.ngcorp.de
*/
function ng_bp_core_widget_welcome($args) {
	global $current_blog;

    extract($args);
	$options = get_blog_option( $current_blog->blog_id, 'ng_bp_core_widget_welcome' );
?>
	<?php echo $before_widget; ?>
	<?php echo $before_title; ?>
		<?php echo $options['ng-w2-title-widget']; ?>
	<?php echo $after_title; ?>

	<?php if ( !is_user_logged_in() ) { ?>

	<span style="font-size:110%"><?php echo $options['ng-w2-title-out'] ?></span>
	<p><?php echo $options['ng-w2-text-out'] ?></p>
	<p class="create-account"><div class="visit generic-button"><a href="<?php bp_signup_page() ?>" title="<?php _e('Create Account', 'buddypress') ?>"><?php _e('Create Account', 'buddypress') ?></a></div></p>
	<?php } ?>
	<?php if ( is_user_logged_in() ) { ?>
	<span style="font-size:110%"><?php echo $options['ng-w2-title-in'] ?></span>
	<p><?php echo $options['ng-w2-text-in'] ?></p>
	<?php } ?>
	<?php echo $after_widget; ?>
<?php

$plugin_dir = basename(dirname(__FILE__));
load_plugin_textdomain( 'kxw', 'wp-content/mu-plugins/kommune' );

}

function ng_bp_core_widget_welcome_control() {
	global $current_blog;
	
	$options = $newoptions = get_blog_option( $current_blog->blog_id, 'ng_bp_core_widget_welcome' );



	if ( $_POST['ng-w2-bp-widget-welcome-submit0'] ) {
		$newoptions['ng-w2-title-widget'] = strip_tags( stripslashes( $_POST['ng-w2-bp-widget-welcome-title-widget'] ) );
	}
	if ( $_POST['ng-w2-bp-widget-welcome-submit1'] ) {
		$newoptions['ng-w2-title-out'] = strip_tags( stripslashes( $_POST['ng-w2-bp-widget-welcome-title-out'] ) );
		$newoptions['ng-w2-text-out'] = stripslashes( wp_filter_post_kses( $_POST['ng-w2-bp-widget-welcome-text-out'] ) );
	}
	if ( $_POST['ng-w2-bp-widget-welcome-submit2'] ) {
		$newoptions['ng-w2-title-in'] = strip_tags( stripslashes( $_POST['ng-w2-bp-widget-welcome-title-in'] ) );
		$newoptions['ng-w2-text-in'] = stripslashes( wp_filter_post_kses( $_POST['ng-w2-bp-widget-welcome-text-in'] ) );
	}
	
	if ( $options != $newoptions ) {
		$options = $newoptions;
		update_blog_option( $current_blog->blog_id, 'ng_bp_core_widget_welcome', $options );
	}
	
	$titlewidget = attribute_escape( $options['ng-w2-title-widget'] );
	$titleout = attribute_escape( $options['ng-w2-title-out'] );
	$textout = attribute_escape( $options['ng-w2-text-out'] );
	$titlein = attribute_escape( $options['ng-w2-title-in'] );
	$textin = attribute_escape( $options['ng-w2-text-in'] );


?>

		<p><label for="ng-w2-bp-widget-welcome-title-widget"><?php _e('Widget Title:', 'kxw'); ?> <input class="widefat" id="ng-w2-bp-widget-welcome-title-widget" name="ng-w2-bp-widget-welcome-title-widget" type="text" value="<?php echo $titlewidget; ?>" /></label></p>
		<input type="hidden" id="ng-w2-bp-widget-welcome-submit0" name="ng-w2-bp-widget-welcome-submit0" value="1" />

		<p><label for="ng-w2-bp-widget-welcome-title-out"><?php _e('Logged Out Title:', 'kxw'); ?> <input class="widefat" id="ng-w2-bp-widget-welcome-title-out" name="ng-w2-bp-widget-welcome-title-out" type="text" value="<?php echo $titleout; ?>" /></label></p>
		<p>
			<label for="ng-w2-bp-widget-welcome-text-out"><?php _e( 'Logged Out Welcome Text:' , 'kxw'); ?>
				<textarea id="ng-w2-bp-widget-welcome-text" name="ng-w2-bp-widget-welcome-text-out" class="widefat" style="height: 100px"><?php echo $textout; ?></textarea>
			</label>
		</p>
		<input type="hidden" id="ng-w2-bp-widget-welcome-submit1" name="ng-w2-bp-widget-welcome-submit1" value="1" />


		<p><label for="ng-w2-bp-widget-welcome-title-in"><?php _e('Logged In Title:', 'kxw'); ?> <input class="widefat" id="ng-w2-bp-widget-welcome-title-in" name="ng-w2-bp-widget-welcome-title-in" type="text" value="<?php echo $titlein; ?>" /></label></p>
		<p>
			<label for="ng-w2-bp-widget-welcome-text-in"><?php _e( 'Logged In Welcome Text:' , 'kxw'); ?>
				<textarea id="ng-w2-bp-widget-welcome-text-in" name="ng-w2-bp-widget-welcome-text-in" class="widefat" style="height: 100px"><?php echo $textin; ?></textarea>
			</label>
		</p>
		<input type="hidden" id="ng-w2-bp-widget-welcome-submit2" name="ng-w2-bp-widget-welcome-submit2" value="1" />
<?php
}

function init_ng_bp_core_widget_welcome() {
	global $current_blog;
	
/* Site welcome widget */
register_sidebar_widget( __('NG BP Welcome Adv', 'buddypress'), 'ng_bp_core_widget_welcome');
register_widget_control( __('NG BP Welcome Adv', 'buddypress'), 'ng_bp_core_widget_welcome_control', 400, 600 );
}

add_action( 'plugins_loaded', 'init_ng_bp_core_widget_welcome' );


